<?php
class HostProcess {
	
	function PipeStdInToHostCommand( $sCommand, $sInput ) {

		$aPipes = array();
		touch( 'error-output.txt' );
		$aHandles = array( 0 => array( 'pipe', 'r' )
						 , 1 => array( 'pipe', 'w' )
						 , 2 => array( 'file', 'error-output.txt', 'a' )
						 );

		$oProcess = proc_open( $sCommand, $aHandles, $aPipes );
		fwrite( $aPipes[0], $sInput );
		fclose( $aPipes[0] );

		$sStdOutResponse = '';
		if ( $aPipes[1] ) {
		   while ( !feof( $aPipes[1] ) ) {
		       $sStdOutResponse .= fgets( $aPipes[1], 4096 );
		   }
		}
			
		fclose( $aPipes[1] );

		$iResult = proc_close( $oProcess );
		
		if ( $sStdOutResponse ) {
			return $sStdOutResponse;
		}
		return $iResult;
	}
}

?>
